package com.mj.mafeed.activity;

import com.mj.mafeed.R;
import com.mj.mafeed.util.SPUtils;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;

/**
 * 设置
 * @author zhaominglei
 * @date 2016-3-3
 * 
 */
public class SettingActivity extends Activity implements OnClickListener {
	@SuppressWarnings("unused")
	private static final String TAG = SettingActivity.class.getSimpleName();
	private ImageView goHome;
	private RelativeLayout profile; //个人资料
	private RelativeLayout editpass; //修改密码
	private String username; //用户名
	@SuppressWarnings("unused")
	private String name; //姓名
	private String sign; //签名
	private Intent intent;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_setting);
		
		init();
	}

	private void init() {
		goHome = (ImageView)findViewById(R.id.setting_gohome);
		profile = (RelativeLayout)findViewById(R.id.setting_profile);
		editpass = (RelativeLayout)findViewById(R.id.setting_editpass);
		
		goHome.setOnClickListener(this);
		profile.setOnClickListener(this);
		editpass.setOnClickListener(this);
		
		username = (String)SPUtils.get(getApplicationContext(), "username", "");
		name = (String)SPUtils.get(getApplicationContext(), "name", "");
		sign = (String)SPUtils.get(getApplicationContext(), "sign", "");
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.setting_gohome:
			intent = new Intent(getApplicationContext(), MainActivity.class);
			intent.putExtra("referer", "SettingActivity");
			startActivity(intent);
			SettingActivity.this.finish();
			break;
		case R.id.setting_profile:
			if (username != null && !username.equals("") && sign != null && !sign.equals("")) {
				intent = new Intent(SettingActivity.this, ProfileActivity.class);
				intent.putExtra("referer", "MemberActivity");
				startActivity(intent);
				SettingActivity.this.finish();
			}
			break;
		case R.id.setting_editpass:
			if (username != null && !username.equals("") && sign != null && !sign.equals("")) {
				intent = new Intent(SettingActivity.this, PasswordActivity.class);
				intent.putExtra("referer", "MemberActivity");
				startActivity(intent);
				SettingActivity.this.finish();
			}
			break;			
		default:
			break;
		}
	}

	@Override
	public void onBackPressed() {
		intent = new Intent(getApplicationContext(), MainActivity.class);
		intent.putExtra("referer", "SettingActivity");
		startActivity(intent);
		SettingActivity.this.finish();
	}
}
